/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Entity;

import java.io.Serializable;
import java.util.Collection;
import javax.persistence.*;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author Leoz
 */
@Entity
@Table(name = "soundtrack")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Soundtrack.findAll", query = "SELECT s FROM Soundtrack s"),
    @NamedQuery(name = "Soundtrack.findByIdSoundtrack", query = "SELECT s FROM Soundtrack s WHERE s.soundtrackPK.idSoundtrack = :idSoundtrack"),
    @NamedQuery(name = "Soundtrack.findByPicture", query = "SELECT s FROM Soundtrack s WHERE s.picture = :picture"),
    @NamedQuery(name = "Soundtrack.findBySongidSong", query = "SELECT s FROM Soundtrack s WHERE s.soundtrackPK.songidSong = :songidSong"),
    @NamedQuery(name = "Soundtrack.findBySongArtistidArtist", query = "SELECT s FROM Soundtrack s WHERE s.soundtrackPK.songArtistidArtist = :songArtistidArtist")})
public class Soundtrack implements Serializable {
    private static final long serialVersionUID = 1L;
    @EmbeddedId
    protected SoundtrackPK soundtrackPK;
    @Basic(optional = false)
    @Column(name = "picture")
    private String picture;
    @JoinColumns({
        @JoinColumn(name = "Song_idSong", referencedColumnName = "idSong", insertable = false, updatable = false),
        @JoinColumn(name = "Song_Artist_idArtist", referencedColumnName = "Artist_idArtist", insertable = false, updatable = false)})
    @ManyToOne(optional = false)
    private Song song;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "soundtrack")
    private Collection<Movie> movieCollection;

    public Soundtrack() {
    }

    public Soundtrack(SoundtrackPK soundtrackPK) {
        this.soundtrackPK = soundtrackPK;
    }

    public Soundtrack(SoundtrackPK soundtrackPK, String picture) {
        this.soundtrackPK = soundtrackPK;
        this.picture = picture;
    }

    public Soundtrack(int idSoundtrack, int songidSong, int songArtistidArtist) {
        this.soundtrackPK = new SoundtrackPK(idSoundtrack, songidSong, songArtistidArtist);
    }

    public SoundtrackPK getSoundtrackPK() {
        return soundtrackPK;
    }

    public void setSoundtrackPK(SoundtrackPK soundtrackPK) {
        this.soundtrackPK = soundtrackPK;
    }

    public String getPicture() {
        return picture;
    }

    public void setPicture(String picture) {
        this.picture = picture;
    }

    public Song getSong() {
        return song;
    }

    public void setSong(Song song) {
        this.song = song;
    }

    @XmlTransient
    public Collection<Movie> getMovieCollection() {
        return movieCollection;
    }

    public void setMovieCollection(Collection<Movie> movieCollection) {
        this.movieCollection = movieCollection;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (soundtrackPK != null ? soundtrackPK.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Soundtrack)) {
            return false;
        }
        Soundtrack other = (Soundtrack) object;
        if ((this.soundtrackPK == null && other.soundtrackPK != null) || (this.soundtrackPK != null && !this.soundtrackPK.equals(other.soundtrackPK))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "entidades.Soundtrack[ soundtrackPK=" + soundtrackPK + " ]";
    }
    
}
